package com.sjgtw.cloud.app.riskReporting.controller;

import com.alibaba.fastjson.JSONObject;
import com.sjgtw.cloud.app.riskReporting.domain.RiskReporting;
import com.sjgtw.cloud.app.riskReporting.domain.RiskTracking;
import com.sjgtw.cloud.app.riskReporting.service.IRiskReportingService;
import com.sjgtw.cloud.app.riskReporting.service.IRiskTrackingService;
import com.sjgtw.cloud.common.core.web.controller.BaseController;
import com.sjgtw.cloud.common.core.web.domain.AjaxResult;
import com.sjgtw.cloud.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 风险上报Controller
 * 
 * @author ruoyi
 * @date 2024-03-17
 */

@RestController
@Api(tags = "6.1 APP、风险上报")
@RequestMapping("/riskReporting")
public class RiskReportingController extends BaseController
{
    @Autowired
    private IRiskReportingService riskReportingService;

    @Autowired
    private IRiskTrackingService riskTrackingService;


    /**
     * 查询风险上报列表-我创建的
     */
    @GetMapping("/list")
    @ApiOperation("APP端---查询风险上报列表")
    public TableDataInfo list(RiskReporting riskReporting)
    {
        startPage();
        List<Map<String,Object>> list = riskReportingService.selectRiskReportingList(riskReporting);
        return getDataTable(list);
    }

    /**
     * 查询风险上报列表-大屏
     * 只返回状态为1和2的，1 已上报  2 已下发
     */
    @GetMapping("/emergencyScreenList")
    @ApiOperation("大屏---查询风险上报列表")
    public AjaxResult emergencyScreenList()
    {
        List<Map<String,Object>> list = riskReportingService.screenList();
        return AjaxResult.success(list);
    }

    /**
     * 查询风险上报详情-大屏
     */
    @GetMapping("/emergencyScreenDetail")
    @ApiOperation("大屏---查询风险上报详情")
    public AjaxResult emergencyScreenDetail(Long id)
    {
        Map<String,Object> map = riskReportingService.emergencyScreenDetail(id);
        return AjaxResult.success(map);
    }


    @PostMapping("/add")
    @ApiOperation("APP端---新增风险上报列表")
    public AjaxResult add(@RequestBody RiskReporting riskReporting)
    {
        return toAjax(riskReportingService.insertRiskReporting(riskReporting));
    }


    /**
     * 修改风险上报
     */
    @PostMapping("/edit")
    @ApiOperation("APP端---修改风险上报")
    public AjaxResult edit(@RequestBody RiskReporting riskReporting)
    {
        return toAjax(riskReportingService.updateRiskReporting(riskReporting));
    }


    /**
     * 风险跟踪
     */
    @PostMapping("/track")
    @ApiOperation("APP端---导航")
    public AjaxResult track(@RequestBody RiskTracking riskTracking)
    {
        return toAjax(riskReportingService.track(riskTracking));
    }

    /**
     * 查询风险跟踪
     */
    @GetMapping("/getMyTrack")
    @ApiOperation("APP端---查询我的风险跟踪")
    public AjaxResult getMyTrack(Long riskId)
    {
        return AjaxResult.success(riskReportingService.getMyTrack(riskId));
    }

    /**
     * 查询通过风险上报id查询风险跟踪
     */
    @GetMapping("/getTracksByRiskIdWithRealLocation")
    @ApiOperation("APP端---查询我的风险跟踪")
    public AjaxResult getTracksByRiskIdWithRealLocation(Long riskId)
    {
        return AjaxResult.success(riskReportingService.getTracksByRiskIdWithRealLocation(riskId));
    }

    /**
     * 查询通过风险上报id查询风险跟踪
     */
    @GetMapping("/getTracksByRiskId")
    @ApiOperation("APP端---查询我的风险跟踪")
    public AjaxResult getTracksByRiskId(Long riskId)
    {
        return AjaxResult.success(riskReportingService.getTracksByRiskId(riskId));
    }


    /**
     * 删除风险上报
     */
    @GetMapping("/delete/{id}")
    @ApiOperation("APP端----删除风险上报")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(riskReportingService.deleteRiskReportingById(id));
    }


    @GetMapping("/getEmergencyTask")
    @ApiOperation("APP端---查询应急处置列表数据-下发到的人")
    public TableDataInfo getEmergencyTask(RiskReporting riskReporting)
    {
        startPage();
        List<Map<String,Object>> list = riskReportingService.getEmergencyTask(riskReporting);
        return getDataTable(list);
    }

    @GetMapping("/confirmTask")
    @ApiOperation("APP端---确认应急处置")
    public AjaxResult confirmTask( Long id)
    {
        return toAjax(riskReportingService.confirmTask(id));
    }

    /**
     * 查询应急任务管理列表
     */
    @GetMapping("/taskManagementList")
    @ApiOperation("Web端---查询应急任务管理列表")
    public TableDataInfo taskManagementList(RiskReporting riskReporting)
    {
        startPage();
        List<Map<String,Object>> list = riskReportingService.selectTaskManagementList(riskReporting);
        return getDataTable(list);
    }

    @GetMapping("/disposalCompleted")
    @ApiOperation("WEb端---处置完成任一阶段的任务")
    public AjaxResult disposalCompleted(Long id)
    {
        return toAjax(riskReportingService.finishTask(id));
    }


    @PostMapping("/taskDistribute")
    @ApiOperation("Web端---下发应急任务/已下发但未在APP端确认的再次下发亦可以调用此接口{\n" +
            "  \"id\": 7,\n" +
            "  \"distributeUserIds\": \"1,2\",\n" +
            "}")
    public AjaxResult taskDistribute(@RequestBody JSONObject jsonObject)
    {
        return toAjax(riskReportingService.taskDistribute(jsonObject));
    }


    @GetMapping("/getTaskDistributeUser")
    @ApiOperation("Web端---点击“已下发”获取应急任务下发人员列表数据")
    public TableDataInfo getTaskDistributeUser(Long id)
    {
        startPage();
        List<Map<String,Object>> list = riskReportingService.getTaskDistributeUser(id);
        if(list == null){
            return new TableDataInfo();
        }else{
            return getDataTable(list);
        }

    }





}
